package com.xunfang.utils;

import com.xunfang.bean.Student;

import java.util.List;

/**
 * @Author lss
 * @CreateTime 2024/6/12
 * @Description 分页工具类
 */
public class PagingQueryBean {


    //每页显示条数
    private int pageSize;
    //当前页
    private int currentPage;
    //总条数
    private int totalSize;
    //索引
    private int index;
    //总页数
    private int totalPage;
    //上一页
    private int prePage;
    //下一页
    private int nextPage;

    List<Student> studentList;

    //提供一个有参构造(每页显示条数,当前页,总条数) 将七个属性都初始化好
    //目的  需要分页的参数就不需要进行计算了，直接从工具类中拿取即可
    public PagingQueryBean(int pageSize,int currentPage,int totalSize) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.totalSize = totalSize;

        //索引
        this.index = (currentPage - 1) * pageSize;
        //上一页
        this.prePage = currentPage <= 1 ? 1 : currentPage - 1;
        //总页数
        this.totalPage = totalSize / pageSize + (totalSize % pageSize == 0 ? 0 : 1);

        //下一页
        this.nextPage = (currentPage >= totalPage ? totalPage : currentPage + 1);


    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    @Override
    public String toString() {
        return "PagingQueryBean{" +
                "pageSize=" + pageSize +
                ", currentPage=" + currentPage +
                ", totalSize=" + totalSize +
                ", index=" + index +
                ", totalPage=" + totalPage +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                '}';
    }
}
